import { Vue } from '@sentry/vue/dist/types';
import * as Sentry from '@sentry/vue';
import { Integrations } from '@sentry/tracing';
import getUserInfo from '../getUserInfo';
import { qqnews } from '../ua';
import { getNewsAppBaseParams } from './beacon';
export default class SentryVue {
  constructor(app: Vue) {
    if (process.env.NODE_ENV !== 'development') {
      // sentry 注入用户
      getUserInfo('all', false);
      if (qqnews) {
        // 新闻客户端注入信息
        getNewsAppBaseParams().then(({
          QIMEI36, appNetwork, appVersion, deviceId, mediaId, omgid, openid, qquin, suid, uid, systemVersion,
        }) => {
          Sentry.setContext('Tencent News', {
            appVersion,
            appNetwork,
            systemVersion,
            uid,
            openid,
            qquin,
            suid,
            omgid,
            mediaId,
            deviceId,
            QIMEI36,
          });
        });
      }
      Sentry.init({
        app,
        dsn: 'https://c432f26c923f459f8d2f83ac8218a8d9@report.url.cn/sentry/3635',
        // @ts-ignore
        release: SENTRY_VERSION,
        environment: process.env.NODE_ENV,
        // maxBreadcrumbs: 50,
        // tracesSampleRate: 1,
        integrations: [
          new Integrations.BrowserTracing({
            // routingInstrumentation: Sentry.vueRouterInstrumentation(router),
          }),
        ],
        // ignoreErrors: [/^NotAllowedError/],
        beforeBreadcrumb(breadcrumb) {
          // 忽略console.log
          if (breadcrumb.category === 'console' && breadcrumb.level === 'log') return null;
          // 忽略埋点
          if (breadcrumb.category === 'xhr' && /oth.eve.mdt.qq.com|otheve.beacon.qq.com/.test(breadcrumb.data!.url)) return null;
          return breadcrumb;
        },
      });
    }
  }
}
